
<!DOCTYPE html>


<html lang="zh-CN" data-content_root="./" >

  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
    <link href="_static/taiji.png" sizes="360x360" rel="icon" type="image/png">
    <title>简介 &#8212; YiJingFramework. PrimitiveTypes</title>
  
  
  
  <script data-cfasync="false">
    document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
    document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
  </script>
  
  <!-- Loaded before other Sphinx assets -->
  <link href="_static/styles/theme.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link href="_static/styles/bootstrap.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
<link href="_static/styles/pydata-sphinx-theme.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />

  
  <link href="_static/vendor/fontawesome/6.5.1/css/all.min.css?digest=8d27b9dea8ad943066ae" rel="stylesheet" />
  <link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.5.1/webfonts/fa-solid-900.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.5.1/webfonts/fa-brands-400.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="_static/vendor/fontawesome/6.5.1/webfonts/fa-regular-400.woff2" />

    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=72bcf2f2" />
    <link rel="stylesheet" type="text/css" href="_static/styles/sphinx-book-theme.css?v=384b581d" />
    <link rel="stylesheet" type="text/css" href="_static/nbsphinx-code-cells.css" />
  
  <!-- Pre-loaded scripts that we'll load fully later -->
  <link rel="preload" as="script" href="_static/scripts/bootstrap.js?digest=8d27b9dea8ad943066ae" />
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=8d27b9dea8ad943066ae" />
  <script src="_static/vendor/fontawesome/6.5.1/js/all.min.js?digest=8d27b9dea8ad943066ae"></script>

    <script src="_static/documentation_options.js?v=946197a6"></script>
    <script src="_static/doctools.js?v=888ff710"></script>
    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="_static/scripts/sphinx-book-theme.js?v=efea14e4"></script>
    <script src="_static/translations.js?v=beaddf03"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script>window.MathJax = {"tex": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true}, "options": {"ignoreHtmlClass": "tex2jax_ignore|mathjax_ignore|document", "processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
    <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
    <script>DOCUMENTATION_OPTIONS.pagename = 'introduction';</script>
    <link rel="index" title="索引" href="genindex.html" />
    <link rel="search" title="搜索" href="search.html" />
    <link rel="next" title="Gua.ToBytes 的实现细节" href="implementation_details_of_Gua.ToBytes.html" />
    <link rel="prev" title="PrimitiveTypes" href="index.html" />
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <meta name="docsearch:language" content="zh-CN"/>
  </head>
  
  
  <body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">

  
  
  <a id="pst-skip-link" class="skip-link" href="#main-content">Skip to main content</a>
  
  <div id="pst-scroll-pixel-helper"></div>
  
  <button type="button" class="btn rounded-pill" id="pst-back-to-top">
    <i class="fa-solid fa-arrow-up"></i>
    Back to top
  </button>

  
  <input type="checkbox"
          class="sidebar-toggle"
          name="__primary"
          id="__primary"/>
  <label class="overlay overlay-primary" for="__primary"></label>
  
  <input type="checkbox"
          class="sidebar-toggle"
          name="__secondary"
          id="__secondary"/>
  <label class="overlay overlay-secondary" for="__secondary"></label>
  
  <div class="search-button__wrapper">
    <div class="search-button__overlay"></div>
    <div class="search-button__search-container">
<form class="bd-search d-flex align-items-center"
      action="search.html"
      method="get">
  <i class="fa-solid fa-magnifying-glass"></i>
  <input type="search"
         class="form-control"
         name="q"
         id="search-input"
         placeholder="Search..."
         aria-label="Search..."
         autocomplete="off"
         autocorrect="off"
         autocapitalize="off"
         spellcheck="false"/>
  <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form></div>
  </div>
  
    <header class="bd-header navbar navbar-expand-lg bd-navbar">
    </header>
  

  <div class="bd-container">
    <div class="bd-container__inner bd-page-width">
      
      
      
      <div class="bd-sidebar-primary bd-sidebar">
        

  
  <div class="sidebar-header-items sidebar-primary__section">
    
    
    
    
  </div>
  
    <div class="sidebar-primary-items__start sidebar-primary__section">
        <div class="sidebar-primary-item">

  

<a class="navbar-brand logo" href="index.html">
  
  
  
  
  
  
    <p class="title logo__title">YiJingFramework. PrimitiveTypes</p>
  
</a></div>
        <div class="sidebar-primary-item">

 <script>
 document.write(`
   <button class="btn navbar-btn search-button-field search-button__button" title="搜索" aria-label="搜索" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <i class="fa-solid fa-magnifying-glass"></i>
    <span class="search-button__default-text">搜索</span>
    <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
   </button>
 `);
 </script></div>
        <div class="sidebar-primary-item"><nav class="bd-links bd-docs-nav" aria-label="Main">
    <div class="bd-toc-item navbar-nav active">
        <p aria-level="2" class="caption" role="heading"><span class="caption-text">主要页面</span></p>
<ul class="current nav bd-sidenav">
<li class="toctree-l1 current active"><a class="current reference internal" href="#">简介</a></li>
</ul>
<p aria-level="2" class="caption" role="heading"><span class="caption-text">其他信息</span></p>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="implementation_details_of_Gua.ToBytes.html"><code class="docutils literal notranslate"><span class="pre">Gua.ToBytes</span></code> 的实现细节</a></li>
</ul>

    </div>
</nav></div>
    </div>
  
  
  <div class="sidebar-primary-items__end sidebar-primary__section">
  </div>
  
  <div id="rtd-footer-container"></div>


      </div>
      
      <main id="main-content" class="bd-main">
        
        

<div class="sbt-scroll-pixel-helper"></div>

          <div class="bd-content">
            <div class="bd-article-container">
              
              <div class="bd-header-article">
<div class="header-article-items header-article__inner">
  
    <div class="header-article-items__start">
      
        <div class="header-article-item"><label class="sidebar-toggle primary-toggle btn btn-sm" for="__primary" title="Toggle primary sidebar" data-bs-placement="bottom" data-bs-toggle="tooltip">
  <span class="fa-solid fa-bars"></span>
</label></div>
      
    </div>
  
  
    <div class="header-article-items__end">
      
        <div class="header-article-item">

<div class="article-header-buttons">


<a href="https://github.com/YiJingFramework/PrimitiveTypes.git" target="_blank"
   class="btn btn-sm btn-source-repository-button"
   title="源码库"
   data-bs-placement="bottom" data-bs-toggle="tooltip"
>
  

<span class="btn__icon-container">
  <i class="fab fa-github"></i>
  </span>

</a>






<div class="dropdown dropdown-download-buttons">
  <button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-label="下载此页面">
    <i class="fas fa-download"></i>
  </button>
  <ul class="dropdown-menu">
      
      
      
      <li><a href="_sources/introduction.ipynb" target="_blank"
   class="btn btn-sm btn-download-source-button dropdown-item"
   title="下载源文件"
   data-bs-placement="left" data-bs-toggle="tooltip"
>
  

<span class="btn__icon-container">
  <i class="fas fa-file"></i>
  </span>
<span class="btn__text-container">.ipynb</span>
</a>
</li>
      
      
      
      
      <li>
<button onclick="window.print()"
  class="btn btn-sm btn-download-pdf-button dropdown-item"
  title="列印成 PDF"
  data-bs-placement="left" data-bs-toggle="tooltip"
>
  

<span class="btn__icon-container">
  <i class="fas fa-file-pdf"></i>
  </span>
<span class="btn__text-container">.pdf</span>
</button>
</li>
      
  </ul>
</div>




<button onclick="toggleFullScreen()"
  class="btn btn-sm btn-fullscreen-button"
  title="全屏模式"
  data-bs-placement="bottom" data-bs-toggle="tooltip"
>
  

<span class="btn__icon-container">
  <i class="fas fa-expand"></i>
  </span>

</button>



<script>
document.write(`
  <button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
  </button>
`);
</script>


<script>
document.write(`
  <button class="btn btn-sm navbar-btn search-button search-button__button" title="搜索" aria-label="搜索" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <i class="fa-solid fa-magnifying-glass fa-lg"></i>
  </button>
`);
</script>
<label class="sidebar-toggle secondary-toggle btn btn-sm" for="__secondary"title="Toggle secondary sidebar" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <span class="fa-solid fa-list"></span>
</label>
</div></div>
      
    </div>
  
</div>
</div>
              
              

<div id="jb-print-docs-body" class="onlyprint">
    <h1>简介</h1>
    <!-- Table of contents -->
    <div id="print-main-content">
        <div id="jb-print-toc">
            
            <div>
                <h2> 目录 </h2>
            </div>
            <nav aria-label="Page">
                <ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#五行">五行</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#天干地支">天干地支</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#阴阳">阴阳</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#卦">卦</a></li>
</ul>
            </nav>
        </div>
    </div>
</div>

              
                
<div id="searchbox"></div>
                <article class="bd-article">
                  
  <section id="简介">
<h1>简介<a class="headerlink" href="#简介" title="Link to this heading">#</a></h1>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="err">#</span><span class="n">r</span><span class="w"> </span><span class="s">&quot;nuget:YiJingFramework.PrimitiveTypes&quot;</span>
<span class="k">using</span><span class="w"> </span><span class="nn">YiJingFramework.PrimitiveTypes</span><span class="p">;</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area rendered_html docutils container">
<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>YiJingFramework.PrimitiveTypes, 4.0.1</span></li></ul></div></div></div>
</div>
<p>此包提供了一些关于易学的基本类型，包括阴阳、五行、天干、地支和卦等。这些类型都有比较完整的字符串转换、整形转换、相互比较等功能。不过，这个包的目的是提供类型本身而非它们相互之间的关联，比如没有取干支阴阳五行、判断五行生克等功能。这些功能被置于 <a class="reference external" href="https://yjfwk.yueyinqiu.top/EntityRelations/">YiJingFramework.EntityRelations</a> 中。</p>
<section id="五行">
<h2>五行<a class="headerlink" href="#五行" title="Link to this heading">#</a></h2>
<p>以五行为例，可以用以下方式直接获取 <code class="docutils literal notranslate"><span class="pre">Wuxing</span></code>，或者把字符串和整形数字转换为 <code class="docutils literal notranslate"><span class="pre">Wuxing</span></code>：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">mu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Mu</span><span class="p">;</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">mu</span><span class="p">);</span>

<span class="kt">var</span><span class="w"> </span><span class="n">shui</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Parse</span><span class="p">(</span><span class="s">&quot; 水 \t &quot;</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">shui</span><span class="p">);</span>

<span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Wuxing</span><span class="p">.</span><span class="n">TryParse</span><span class="p">(</span><span class="s">&quot; jin \t &quot;</span><span class="p">,</span><span class="w"> </span><span class="k">out</span><span class="w"> </span><span class="kt">var</span><span class="w"> </span><span class="n">jin</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">jin</span><span class="p">);</span>

<span class="kt">var</span><span class="w"> </span><span class="n">huo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">Wuxing</span><span class="p">)</span><span class="m">6</span><span class="p">;</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">huo</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Mu
Shui
Jin
Huo
</pre></div></div>
</div>
<p>虽然五行只有五个，但是倒数第二行的 <code class="docutils literal notranslate"><span class="pre">(Wuxing)6</span></code> 也可以正常运行。其具体的转化方式是这样的：</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">i</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">w=(Wuxing)i</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">(int)w</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
<tr class="row-odd"><td><p>-2</p></td>
<td><p>金</p></td>
<td><p>3</p></td>
</tr>
<tr class="row-even"><td><p>-1</p></td>
<td><p>水</p></td>
<td><p>4</p></td>
</tr>
<tr class="row-odd"><td><p><strong>0</strong></p></td>
<td><p><strong>木</strong></p></td>
<td><p><strong>0</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>1</strong></p></td>
<td><p><strong>火</strong></p></td>
<td><p><strong>1</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>2</strong></p></td>
<td><p><strong>土</strong></p></td>
<td><p><strong>2</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>3</strong></p></td>
<td><p><strong>金</strong></p></td>
<td><p><strong>3</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>4</strong></p></td>
<td><p><strong>水</strong></p></td>
<td><p><strong>4</strong></p></td>
</tr>
<tr class="row-even"><td><p>5</p></td>
<td><p>木</p></td>
<td><p>0</p></td>
</tr>
<tr class="row-odd"><td><p>6</p></td>
<td><p>火</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
</tbody>
</table>
<p>这种转换主要是可以利用于直接用数学上的计算来获取生克之类，以及更方便通过 <code class="docutils literal notranslate"><span class="pre">switch</span></code> 进行匹配。一般情况下是不建议使用的，因为这些数字没有直接的实际意义。其提供的运算符 <code class="docutils literal notranslate"><span class="pre">+</span></code> 和 <code class="docutils literal notranslate"><span class="pre">-</span></code> 也是如此。</p>
<p>同时，其默认的 <code class="docutils literal notranslate"><span class="pre">ToString</span></code> 行为是转为首字母大写的拼音。可以传入 <code class="docutils literal notranslate"><span class="pre">&quot;C&quot;</span></code> 以使用中文：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Mu</span><span class="p">.</span><span class="n">ToString</span><span class="p">(</span><span class="s">&quot;G&quot;</span><span class="p">));</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Mu</span><span class="p">.</span><span class="n">ToString</span><span class="p">(</span><span class="s">&quot;C&quot;</span><span class="p">));</span>

<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Huo</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{Wuxing.Huo:C}&quot;</span><span class="p">);</span>

<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Tu</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{Wuxing.Tu:C}&quot;</span><span class="p">);</span>

<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Jin</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{Wuxing.Jin:C}&quot;</span><span class="p">);</span>

<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">.</span><span class="n">Shui</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{Wuxing.Shui:C}&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Mu木
Huo火
Tu土
Jin金
Shui水
</pre></div></div>
</div>
<blockquote>
<div><p>其他语言不会在这个包中支持，不过自己实现一个方法也是相对方便的，也可以借助 <a class="reference external" href="https://yjfwk.yueyinqiu.top/EntityRelations/">YiJingFramework.EntityRelations</a> 提供的扩展方法加以支持。</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">Wuxing</span></code> 提供的 <code class="docutils literal notranslate"><span class="pre">Parse</span></code> 和 <code class="docutils literal notranslate"><span class="pre">TryParse</span></code> 方法，可以解析以上所有的结果，不区分大小写，首尾可以有空白字符。</p>
<p>除此之外，<code class="docutils literal notranslate"><span class="pre">Wuxing</span></code> 实现了 <code class="docutils literal notranslate"><span class="pre">IComparable</span></code> 、 <code class="docutils literal notranslate"><span class="pre">IEquatable</span></code> 和 <code class="docutils literal notranslate"><span class="pre">IEqualityOperators</span></code> 等接口，可以正确地支持排序和比较等行为，可以使用 <code class="docutils literal notranslate"><span class="pre">==</span></code> 等运算符进行比较。</p>
</section>
<section id="天干地支">
<h2>天干地支<a class="headerlink" href="#天干地支" title="Link to this heading">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">Tiangan</span></code> 和 <code class="docutils literal notranslate"><span class="pre">Dizhi</span></code> 与 <code class="docutils literal notranslate"><span class="pre">Wuxing</span></code> 是非常相似的：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">jia</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Tiangan</span><span class="p">.</span><span class="n">Jia</span><span class="p">;</span>
<span class="kt">var</span><span class="w"> </span><span class="n">yi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jia</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>
<span class="kt">var</span><span class="w"> </span><span class="n">bing</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">yi</span><span class="p">.</span><span class="n">Next</span><span class="p">();</span>
<span class="kt">var</span><span class="w"> </span><span class="n">ding</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jia</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="m">13</span><span class="p">;</span>
<span class="kt">var</span><span class="w"> </span><span class="n">wu</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ding</span><span class="p">.</span><span class="n">Next</span><span class="p">(</span><span class="o">-</span><span class="m">9</span><span class="p">);</span>

<span class="kt">var</span><span class="w"> </span><span class="n">gui</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">jia</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">1</span><span class="p">;</span>

<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{jia} {yi} {bing} {ding:C}{wu:C}{gui:C}&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Jia Yi Bing 丁戊癸
</pre></div></div>
</div>
<p>干支也支持超过范围的值。但是与五行不同，它的序数是具有一定意义的，因此提供了 <code class="docutils literal notranslate"><span class="pre">Index</span></code> 属性和 <code class="docutils literal notranslate"><span class="pre">FromIndex</span></code> 方法。它的值是从 <code class="docutils literal notranslate"><span class="pre">1</span></code> 开始的，具体如下表：</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">i</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">t=Tiangan.FromIndex(i)</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">t.Index</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
<tr class="row-odd"><td><p>-1</p></td>
<td><p>壬</p></td>
<td><p>9</p></td>
</tr>
<tr class="row-even"><td><p>0</p></td>
<td><p>癸</p></td>
<td><p>10</p></td>
</tr>
<tr class="row-odd"><td><p><strong>1</strong></p></td>
<td><p><strong>甲</strong></p></td>
<td><p><strong>1</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>2</strong></p></td>
<td><p><strong>乙</strong></p></td>
<td><p><strong>2</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>3</strong></p></td>
<td><p><strong>丙</strong></p></td>
<td><p><strong>3</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>4</strong></p></td>
<td><p><strong>丁</strong></p></td>
<td><p><strong>4</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>5</strong></p></td>
<td><p><strong>戊</strong></p></td>
<td><p><strong>5</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>6</strong></p></td>
<td><p><strong>己</strong></p></td>
<td><p><strong>6</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>7</strong></p></td>
<td><p><strong>庚</strong></p></td>
<td><p><strong>7</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>8</strong></p></td>
<td><p><strong>辛</strong></p></td>
<td><p><strong>8</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>9</strong></p></td>
<td><p><strong>壬</strong></p></td>
<td><p><strong>9</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>10</strong></p></td>
<td><p><strong>癸</strong></p></td>
<td><p><strong>10</strong></p></td>
</tr>
<tr class="row-odd"><td><p>11</p></td>
<td><p>甲</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p>12</p></td>
<td><p>乙</p></td>
<td><p>2</p></td>
</tr>
<tr class="row-odd"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p><code class="docutils literal notranslate"><span class="pre">i</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">d=Dizhi.FromIndex(i)</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">d.Index</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
<tr class="row-odd"><td><p>-1</p></td>
<td><p>戌</p></td>
<td><p>11</p></td>
</tr>
<tr class="row-even"><td><p>0</p></td>
<td><p>亥</p></td>
<td><p>12</p></td>
</tr>
<tr class="row-odd"><td><p><strong>1</strong></p></td>
<td><p><strong>子</strong></p></td>
<td><p><strong>1</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>2</strong></p></td>
<td><p><strong>丑</strong></p></td>
<td><p><strong>2</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>3</strong></p></td>
<td><p><strong>寅</strong></p></td>
<td><p><strong>3</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>4</strong></p></td>
<td><p><strong>卯</strong></p></td>
<td><p><strong>4</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>5</strong></p></td>
<td><p><strong>辰</strong></p></td>
<td><p><strong>5</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>6</strong></p></td>
<td><p><strong>巳</strong></p></td>
<td><p><strong>6</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>7</strong></p></td>
<td><p><strong>午</strong></p></td>
<td><p><strong>7</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>8</strong></p></td>
<td><p><strong>未</strong></p></td>
<td><p><strong>8</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>9</strong></p></td>
<td><p><strong>申</strong></p></td>
<td><p><strong>9</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>10</strong></p></td>
<td><p><strong>酉</strong></p></td>
<td><p><strong>10</strong></p></td>
</tr>
<tr class="row-odd"><td><p><strong>11</strong></p></td>
<td><p><strong>戌</strong></p></td>
<td><p><strong>11</strong></p></td>
</tr>
<tr class="row-even"><td><p><strong>12</strong></p></td>
<td><p><strong>亥</strong></p></td>
<td><p><strong>12</strong></p></td>
</tr>
<tr class="row-odd"><td><p>13</p></td>
<td><p>子</p></td>
<td><p>1</p></td>
</tr>
<tr class="row-even"><td><p>14</p></td>
<td><p>丑</p></td>
<td><p>2</p></td>
</tr>
<tr class="row-odd"><td><p>…</p></td>
<td><p>…</p></td>
<td><p>…</p></td>
</tr>
</tbody>
</table>
<p>不过，由于结构体的限制，在使用 <code class="docutils literal notranslate"><span class="pre">default</span></code> 进行创建时，其内部值会为零。因此，上述操作必然是存在额外开销的。考虑到这一问题，我们仍然提供了强制转换运算符，而它返回的结果始终是 <code class="docutils literal notranslate"><span class="pre">Index</span> <span class="pre">-</span> <span class="pre">1</span></code>：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">((</span><span class="kt">int</span><span class="p">)</span><span class="k">default</span><span class="p">(</span><span class="n">Wuxing</span><span class="p">));</span>
<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">(</span><span class="k">default</span><span class="p">(</span><span class="n">Tiangan</span><span class="p">).</span><span class="n">Index</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">Dizhi</span><span class="p">.</span><span class="n">FromIndex</span><span class="p">(</span><span class="m">1</span><span class="p">).</span><span class="n">ToString</span><span class="p">(</span><span class="s">&quot;C&quot;</span><span class="p">));</span>

<span class="n">Console</span><span class="p">.</span><span class="n">Write</span><span class="p">((</span><span class="kt">int</span><span class="p">)</span><span class="k">default</span><span class="p">(</span><span class="n">Tiangan</span><span class="p">));</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(((</span><span class="n">Dizhi</span><span class="p">)</span><span class="m">0</span><span class="p">).</span><span class="n">ToString</span><span class="p">(</span><span class="s">&quot;C&quot;</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
01子
0子
</pre></div></div>
</div>
<p>上两例也可以看到，<code class="docutils literal notranslate"><span class="pre">ToString</span></code> 方法也支持拼音和中文两种，具体结果如下表：</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>天干</p></th>
<th class="head"><p>默认或<code class="docutils literal notranslate"><span class="pre">&quot;G&quot;</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">&quot;C&quot;</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>甲</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Jia&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;甲&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>乙</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Yi&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;乙&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>丙</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Bing&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;丙&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>丁</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Ding&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;丁&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>戊</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Wu&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;戊&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>己</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Ji&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;己&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>庚</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Geng&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;庚&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>辛</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Xin&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;辛&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>壬</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Ren&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;壬&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>癸</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Gui&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;癸&quot;</span></code></p></td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>地支</p></th>
<th class="head"><p>默认或<code class="docutils literal notranslate"><span class="pre">&quot;G&quot;</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">&quot;C&quot;</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>子</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Zi&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;子&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>丑</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Chou&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;丑&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>寅</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Yin&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;寅&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>卯</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Mao&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;卯&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>辰</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Chen&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;辰&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>巳</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Si&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;巳&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>午</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Wu&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;午&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>未</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Wei&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;未&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>申</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Shen&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;申&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>酉</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;You&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;酉&quot;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>戌</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Xu&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;戌&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>亥</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Hai&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;亥&quot;</span></code></p></td>
</tr>
</tbody>
</table>
</section>
<section id="阴阳">
<h2>阴阳<a class="headerlink" href="#阴阳" title="Link to this heading">#</a></h2>
<p>阴阳由于只存在两者可能，因此 <code class="docutils literal notranslate"><span class="pre">Yinyang</span></code> 与先前的五行和干支略有不同，内部是使用布尔值来表示的。对外它提供 <code class="docutils literal notranslate"><span class="pre">IsYang</span></code> 属性取得此值，也提供了相对应的构造方法。</p>
<p>除此之外，它不支持加减运算，但是支持布尔类型所具有的 <code class="docutils literal notranslate"><span class="pre">!</span></code> 运算符，以及 <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> 、 <code class="docutils literal notranslate"><span class="pre">|</span></code> 和 <code class="docutils literal notranslate"><span class="pre">^</span></code> 运算。不过，我们不打算为它实现 <code class="docutils literal notranslate"><span class="pre">operator</span> <span class="pre">true</span></code> 和 <code class="docutils literal notranslate"><span class="pre">operator</span> <span class="pre">false</span></code> ，因为它本身并不是一个布尔值。</p>
<p>具体 <code class="docutils literal notranslate"><span class="pre">Yinyang</span></code> 的 <code class="docutils literal notranslate"><span class="pre">ToString</span></code> 结果如下表：</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>阴阳</p></th>
<th class="head"><p>默认或<code class="docutils literal notranslate"><span class="pre">&quot;G&quot;</span></code></p></th>
<th class="head"><p><code class="docutils literal notranslate"><span class="pre">&quot;C&quot;</span></code></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>阴</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Yin&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;阴&quot;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>阳</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;Yang&quot;</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&quot;阳&quot;</span></code></p></td>
</tr>
</tbody>
</table>
</section>
<section id="卦">
<h2>卦<a class="headerlink" href="#卦" title="Link to this heading">#</a></h2>
<p>卦是由若干具有阴阳属性的爻组成的。通常来说，我们常用的是具有三根爻的八卦和六根爻的六十四卦，但是这里给出的 <code class="docutils literal notranslate"><span class="pre">Gua</span></code> 支持任意的爻数。</p>
<blockquote>
<div><p><a class="reference external" href="https://yjfwk.yueyinqiu.top/PrimitiveTypes.GuaWithFixedCount/">YiJingFramework.PrimitiveTypes.GuaWithFixedCount</a> 提供了只支持固定爻数的卦，从而能够及时在编译期发现错误。</p>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">Gua</span></code> 其实就是一个不可变的有序的爻的集合，可以通过以下方式来创建 <code class="docutils literal notranslate"><span class="pre">Gua</span></code>：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">dui</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gua</span><span class="p">(</span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yang</span><span class="p">,</span><span class="w"> </span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yang</span><span class="p">,</span><span class="w"> </span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yin</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">dui</span><span class="p">);</span>

<span class="kt">var</span><span class="w"> </span><span class="n">qian</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gua</span><span class="p">(</span><span class="n">Enumerable</span><span class="p">.</span><span class="n">Repeat</span><span class="p">(</span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yang</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">));</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">qian</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
110
111111
</pre></div></div>
</div>
<p><strong>注意：虽然顺序本身是可以颠倒的，但是使用时请统一按照序号小的在下、序号大的在上，即易气上行、先来居下、由下至上的顺序（所谓上下即常用的卦画的上下），如上例“阳阳阴”表示兑卦而非巽卦。包括</strong> <a class="reference external" href="https://yjfwk.yueyinqiu.top/EntityRelations/">YiJingFramework.EntityRelations</a> <strong>和</strong> <a class="reference external" href="https://yjfwk.yueyinqiu.top/Annotating.Zhouyi/">YiJingFramework.Annotating.Zhouyi</a> <strong>在内的各种包，都是按照由下至上的理解方式来提供功能的。</strong></p>
<p><code class="docutils literal notranslate"><span class="pre">Gua</span></code> 实现了 <code class="docutils literal notranslate"><span class="pre">IReadOnlyList</span></code> ，因此可以当作列表使用。无论是通过索引器访问，还是通过 <code class="docutils literal notranslate"><span class="pre">foreach</span></code> 遍历，都是由下至上的顺序：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="kt">var</span><span class="w"> </span><span class="n">dui</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gua</span><span class="p">(</span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yang</span><span class="p">,</span><span class="w"> </span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yang</span><span class="p">,</span><span class="w"> </span><span class="n">Yinyang</span><span class="p">.</span><span class="n">Yin</span><span class="p">);</span>

<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">dui</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{dui[0]} {dui[1]} {dui[2]}&quot;</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="s">$&quot;{string.Join(&#39;,&#39;, dui)}&quot;</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
110
Yang Yang Yin
Yang,Yang,Yin
</pre></div></div>
</div>
<p>上例中我们也已经看到了 <code class="docutils literal notranslate"><span class="pre">Gua.ToString</span></code> 的效果，它使用 <code class="docutils literal notranslate"><span class="pre">'1'</span></code> 表示阳爻、 <code class="docutils literal notranslate"><span class="pre">'0'</span></code> 表示阴爻，从而把卦转为一个相对简短的字符串，也是先下后上的顺序。</p>
<p>同时，它也实现了 <code class="docutils literal notranslate"><span class="pre">Parse</span></code> 和 <code class="docutils literal notranslate"><span class="pre">TryParse</span></code> 等方法，以及 <code class="docutils literal notranslate"><span class="pre">IComparable</span></code> 、 <code class="docutils literal notranslate"><span class="pre">IEquatable</span></code> 和 <code class="docutils literal notranslate"><span class="pre">IEqualityOperators</span></code> 等接口，可以使用 <code class="docutils literal notranslate"><span class="pre">==</span></code> 等运算符进行比较。</p>
<p>最后， <code class="docutils literal notranslate"><span class="pre">Gua</span></code> 还可以被转换为 <code class="docutils literal notranslate"><span class="pre">byte[]</span></code>：</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[8]:
</pre></div>
</div>
<div class="input_area highlight-csharp notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="n">IEnumerable</span><span class="o">&lt;</span><span class="n">Yinyang</span><span class="o">&gt;</span><span class="w"> </span><span class="n">GetRandomLines</span><span class="p">()</span>
<span class="p">{</span>
<span class="w">    </span><span class="n">Random</span><span class="w"> </span><span class="n">random</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Random</span><span class="p">(</span><span class="m">0</span><span class="p">);</span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="p">(;</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="p">)</span>
<span class="w">        </span><span class="k">yield</span><span class="w"> </span><span class="nf">return</span><span class="w"> </span><span class="p">(</span><span class="n">Yinyang</span><span class="p">)</span><span class="n">random</span><span class="p">.</span><span class="n">Next</span><span class="p">(</span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">var</span><span class="w"> </span><span class="n">gua</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Gua</span><span class="p">(</span><span class="n">GetRandomLines</span><span class="p">().</span><span class="n">Take</span><span class="p">(</span><span class="m">30</span><span class="p">));</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">gua</span><span class="p">);</span>

<span class="kt">var</span><span class="w"> </span><span class="n">byteArray</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">gua</span><span class="p">.</span><span class="n">ToBytes</span><span class="p">();</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">Convert</span><span class="p">.</span><span class="n">ToHexString</span><span class="p">(</span><span class="n">byteArray</span><span class="p">));</span>

<span class="kt">var</span><span class="w"> </span><span class="n">gua2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Gua</span><span class="p">.</span><span class="n">FromBytes</span><span class="p">(</span><span class="n">byteArray</span><span class="p">);</span>
<span class="n">Console</span><span class="p">.</span><span class="n">WriteLine</span><span class="p">(</span><span class="n">gua</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">gua2</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
111101101000101011101110111110
6F51775F
True
</pre></div></div>
</div>
<p>不过，这种转换一般只会在非常特殊的场合下使用。而且即使需要使用，一般也不需要关注得到的 <code class="docutils literal notranslate"><span class="pre">byte[]</span></code> 具体是什么值，只需要知道它可以正确还原就足够了。如果确实想要了解相关细节，可以点击<a class="reference internal" href="implementation_details_of_Gua.ToBytes.html"><span class="doc">这里</span></a>。</p>
</section>
</section>


                </article>
              

              
              
              
              
                <footer class="prev-next-footer">
                  
<div class="prev-next-area">
    <a class="left-prev"
       href="index.html"
       title="previous page">
      <i class="fa-solid fa-angle-left"></i>
      <div class="prev-next-info">
        <p class="prev-next-subtitle">上一页</p>
        <p class="prev-next-title">PrimitiveTypes</p>
      </div>
    </a>
    <a class="right-next"
       href="implementation_details_of_Gua.ToBytes.html"
       title="next page">
      <div class="prev-next-info">
        <p class="prev-next-subtitle">下一页</p>
        <p class="prev-next-title"><code class="docutils literal notranslate"><span class="pre">Gua.ToBytes</span></code> 的实现细节</p>
      </div>
      <i class="fa-solid fa-angle-right"></i>
    </a>
</div>
                </footer>
              
            </div>
            
            
              
                <div class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">


  <div class="sidebar-secondary-item">
  <div class="page-toc tocsection onthispage">
    <i class="fa-solid fa-list"></i> 目录
  </div>
  <nav class="bd-toc-nav page-toc">
    <ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#五行">五行</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#天干地支">天干地支</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#阴阳">阴阳</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#卦">卦</a></li>
</ul>
  </nav></div>

</div></div>
              
            
          </div>
          <footer class="bd-footer-content">
            
<div class="bd-footer-content__inner container">
  
  <div class="footer-item">
    
  </div>
  
  <div class="footer-item">
    

  </div>
  
  <div class="footer-item">
    
  </div>
  
  <div class="footer-item">
    
<div class="extra_footer">
  这里是 YiJingFramework.PrimitiveTypes 的文档。前往 <a href="https://yjfwk.yueyinqiu.top/">https://yjfwk.yueyinqiu.top/</a> 查看更多项目。
</div>
  </div>
  
</div>
          </footer>
        

      </main>
    </div>
  </div>
  
  <!-- Scripts loaded after <body> so the DOM is not blocked -->
  <script src="_static/scripts/bootstrap.js?digest=8d27b9dea8ad943066ae"></script>
<script src="_static/scripts/pydata-sphinx-theme.js?digest=8d27b9dea8ad943066ae"></script>

  <footer class="bd-footer">
  </footer>
  </body>
</html>